import { http } from "@/utils/http";
import { baseUrlApi } from "@/api/utils";
import { message } from "@/utils/message";
type Result = {
	current_page : number;
	result ?: any;
	per_page ?: number;
	total ?: number;
	data ?: any;
};
type ResultDelete = {
	code : number;
	msg : string;
};
type ResultCreate = {
	code : number;
	msg : string;
};
/** 库房列表 */
export const getWarehouseListApi = (params ?: object) => {
	return http.request<Result>("get", baseUrlApi + "/warehouse/list", {
		params
	});
};

/** 添加*/
export const createWarehouseApi = (data ?: object) => {
	return http.request<ResultCreate>("post", baseUrlApi + "/warehouse/store", {
		data
	})
	.catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};
/** 修改 */
export const updateWarehouseApi = (data ?: object) => {
	return http.request<ResultCreate>("put", baseUrlApi + "/warehouse/update", {
		data
	})
	.catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};
export const delWarehouseApi = (params ?: object) => {
	return http.request<ResultDelete>("delete", baseUrlApi + "/warehouse/delete", {
		params
	})
	.catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};
type Show = {
	code : number;
	msg : string;
	result ?: any;
};
/** 详情 */
export const getWarehouseShowApi = (params ?: object) => {
	return http.request<Show>("get", baseUrlApi + "/warehouse/show", {
		params
	});
};

/** 库区列表 */
export const getWarehouseAreaListApi = (params ?: object) => {
	return http.request<Result>("get", baseUrlApi + "/warehouseArea/list", {
		params
	});
};
/** 库区添加*/
export const createWarehouseAreaApi = (data ?: object) => {
	return http.request<ResultCreate>("post", baseUrlApi + "/warehouseArea/store", {
		data
	})
	.catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};
/** 库区修改 */
export const updateWarehouseAreaApi = (data ?: object) => {
	return http.request<ResultCreate>("put", baseUrlApi + "/warehouseArea/update", {
		data
	})
	.catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};
/** 库区删除 */
export const delWarehouseAreaApi = (params ?: object) => {
	return http.request<ResultDelete>("delete", baseUrlApi + "/warehouseArea/delete", {
		params
	})
	.catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};
/** 库区详情 */
export const getWarehouseAreaShowApi = (params ?: object) => {
	return http.request<Show>("get", baseUrlApi + "/warehouseArea/show", {
		params
	});
};
/** 库位列表 */
export const getWarehouseLocationListApi = (params ?: object) => {
	return http.request<Result>("get", baseUrlApi + "/warehouseLocation/list", {
		params
	});
};
/** 库位添加*/
export const createWarehouseLocationApi = (data ?: object) => {
	return http.request<ResultCreate>("post", baseUrlApi + "/warehouseLocation/store", {
		data
	})
	.catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};
/** 库位修改 */
export const updateWarehouseLocationApi = (data ?: object) => {
	return http.request<ResultCreate>("put", baseUrlApi + "/warehouseLocation/update", {
		data
	})
	.catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};
/** 库位删除 */
export const delWarehouseLocationApi = (params ?: object) => {
	return http.request<ResultDelete>("delete", baseUrlApi + "/warehouseLocation/delete", {
		params
	})
	.catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};
/** 库位详情 */
export const getWarehouseLocationShowApi = (params ?: object) => {
	return http.request<Show>("get", baseUrlApi + "/warehouseLocation/show", {
		params
	});
};
/** 库位状态更新 */
export const updateStatusWarehouseLocationApi = (params ?: object) => {
	return http.request<ResultCreate>("put", baseUrlApi + "/warehouseLocation/updateStatus", {
		params
	}).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/**
 * 
 * 库存盘点
 * #########################
 * #########################
 * 
*/
/** 库存盘点列表 */
export const getWarehouseCheckListApi = (params ?: object) => {
	return http.request<Result>("get", baseUrlApi + "/warehouseCheck/list", {
		params
	});
};
/** 库存盘点添加*/
export const createWarehouseCheckApi = (data ?: object) => {
	return http.request<ResultCreate>("post", baseUrlApi + "/warehouseCheck/store", {
		data
	})
	.catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};
/** 库存盘点修改 */
export const updateWarehouseCheckApi = (data ?: object) => {
	return http.request<ResultCreate>("put", baseUrlApi + "/warehouseCheck/update", {
		data
	})
	.catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};
/** 库存盘点删除 */
export const delWarehouseCheckApi = (params ?: object) => {
	return http.request<ResultDelete>("delete", baseUrlApi + "/warehouseCheck/delete", {
		params
	})
	.catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};
/** 库存盘点详情 */
export const getWarehouseCheckShowApi = (params ?: object) => {
	return http.request<Show>("get", baseUrlApi + "/warehouseCheck/show", {
		params
	});
};

/**
 * 
 * 库存看板
 * 更新时间
 * #########################
 * #########################
 * 
*/
export const updateEntryTimeApi = (data ?: object) => {
	return http.request<ResultCreate>("put", baseUrlApi + "/warehouseProduct/updateEntryTime", {
		data
	})
	.catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/**
 * 
 * 库存统计
 * 
 * #########################
 * #########################
 * 
*/
export const getTotalDataApi = (params ?: object) => {
	return http.request<Show>("get", baseUrlApi + "/statistics/warehouse/getTotalData", {
		params
	});
};
/** 库位产品日统计 */
export const getTotalDayDataApi = (params ?: object) => {
	return http.request<Show>("get", baseUrlApi + "/statistics/warehouse/getTotalDayData", {
		params
	});
};
/** 库位产品周统计 */
export const getTotalWeekDataApi = (params ?: object) => {
	return http.request<Show>("get", baseUrlApi + "/statistics/warehouse/getTotalWeekData", {
		params
	});
};